receive()
, called on a channel, will suspend until there is an object
available, then returns that object.
There is a similar receiveOrNull()
function that also suspends until an object
is available, then returns that object. The difference is what happens if
the channel is closed while receive()
or receiveOrNull()
is suspended:
receive()
throws aClosedReceiveChannelException
receiveOrNull()
returnsnull
(which might be confusing ifnull
is a valid object to appear in the channel)
You can learn more about this in:
Tags: